package com.relife.core.entity;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

@Entity
@Table(name = "sys_function")
public class FunctionEntity extends BaseEntity {

	private static final long serialVersionUID = 1L;

	private String name;
	private String url;
	/** 类型 ：字典：menuType **/
	private Integer type;
	private String code;
	private String style;
	private Integer orderBy;
	private List<RoleEntity> role;
	private List<FunctionEntity> children;
	private FunctionEntity parent;

	public FunctionEntity() {
	}

	public FunctionEntity(String id) {
		super.setId(id);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getStyle() {
		return style;
	}

	public void setStyle(String style) {
		this.style = style;
	}

	@OneToMany(mappedBy = "parent", cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
	@OrderBy(value = "orderBy ASC")
	public List<FunctionEntity> getChildren() {
		return children;
	}

	public void setChildren(List<FunctionEntity> children) {
		this.children = children;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "ParentId")
	public FunctionEntity getParent() {
		return parent;
	}

	public void setParent(FunctionEntity parent) {
		this.parent = parent;
	}

	public Integer getType() {
		return type;
	}

	public void setType(Integer type) {
		this.type = type;
	}

	public Integer getOrderBy() {
		return orderBy;
	}

	public void setOrderBy(Integer orderBy) {
		this.orderBy = orderBy;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "sys_function_role", joinColumns = { @JoinColumn(name = "fun_id") }, inverseJoinColumns = { @JoinColumn(name = "role_id") })
	public List<RoleEntity> getRole() {
		return role;
	}

	public void setRole(List<RoleEntity> role) {
		this.role = role;
	}
}
